#include "trainstatuscontroller.h"

TrainStatusController::TrainStatusController(QObject *parent)
    : QObject{parent}
{
    trainStatusView = new TrainStatusView();

    setBrakeIndicator(BrakeIndicatorState::REDBRAKE);
    setSlideIndicator(SlideIndicatorState::SLIP);
    setTrainIntegrityState(TrainIntegrityState::RED);
    setReverseIndicatorState(ReverseIndicatorState::GREEN_REV);
    setARadioCommunicationStatus(ARadioCommunicationStatus::Green_A);
    setBRadioCommunicationStatus(BRadioCommunicationStatus::Green_B);
}

void TrainStatusController::show(QVBoxLayout *vLayout, int w)
{
    vLayout->addWidget(trainStatusView,w);
}

void TrainStatusController::setBrakeIndicator(BrakeIndicatorState state)
{
    switch (state) {
    case BrakeIndicatorState::REDBRAKE:
        trainStatusView->topLabel->setPixmap(QPixmap(":images/1p3.png"));
        break;
    case BrakeIndicatorState::FLASHINGBRAKE:
        trainStatusView->topLabel->setPixmap(QPixmap(""));
        break;
    case BrakeIndicatorState::NONEBRAKE:
        break;
    default:
        break;
    }

}

void TrainStatusController::setSlideIndicator(SlideIndicatorState state)
{
    switch (state) {
    case SlideIndicatorState::BLANK:
        break;
    case SlideIndicatorState::SLIP:
        trainStatusView->label[0]->setPixmap(QPixmap(":images/wheel_slip.png"));
        break;
    case SlideIndicatorState::SLIDE:
        trainStatusView->label[0]->setPixmap(QPixmap(":images/wheel_slide.png"));
        break;
    default:
        break;
    }
}

void TrainStatusController::setTrainIntegrityState(TrainIntegrityState state)
{
    switch (state) {
    case TrainIntegrityState::GREEN:
        trainStatusView->label[1]->setPixmap(QPixmap(":images/train_integrity_ok.png"));
        break;
    case TrainIntegrityState::RED:
        trainStatusView->label[1]->setPixmap(QPixmap(":images/train_integrity_nok.png"));
        break;
    default:
        break;
    }
}

void TrainStatusController::setReverseIndicatorState(ReverseIndicatorState state)
{
    switch (state) {
    case ReverseIndicatorState::BLANK_REV:
        break;
    case ReverseIndicatorState::GREEN_REV:
        trainStatusView->label[2]->setPixmap(QPixmap(":images/rev_permitted.png"));
        break;
    case ReverseIndicatorState::RED_REV:
        trainStatusView->label[2]->setPixmap(QPixmap(":images/rev_protected.png"));
        break;
    default:
        break;
    }
}


void TrainStatusController::setARadioCommunicationStatus(ARadioCommunicationStatus state)
{
    switch (state) {
    case ARadioCommunicationStatus::Green_A:
        trainStatusView-> label[3]->setPixmap(QPixmap(":images/radio_ok_a.png"));
        break;
    case ARadioCommunicationStatus::Light_A:
        trainStatusView-> label[3]->setPixmap(QPixmap(":images/radio_no_comm_a.png"));
        break;
    case ARadioCommunicationStatus::Red_A:
        trainStatusView-> label[3]->setPixmap(QPixmap(":images/radio_fail_a.png"));
        break;
    default:
        break;
    }
}
void TrainStatusController::setBRadioCommunicationStatus(BRadioCommunicationStatus state)
{
    switch (state) {
    case BRadioCommunicationStatus::Green_B:
        trainStatusView->   label[4]->setPixmap(QPixmap(":images/radio_ok_b.png"));
        break;
    case BRadioCommunicationStatus::Light_B:
        trainStatusView->   label[4]->setPixmap(QPixmap(":images/radio_no_comm_b.png"));
        break;
    case BRadioCommunicationStatus::Red_B:
        trainStatusView->   label[4]->setPixmap(QPixmap(":images/radio_fail_b.png"));
        break;
    default:
        break;
    }
}

